package com.matrix.storage.controller;

import com.matrix.common.entity.Result;
import com.matrix.domain.media.oss.StorageFileDTO;
import com.matrix.storage.constant.StorageError;
import com.matrix.storage.dto.StorageSpaceDTO;
import com.matrix.storage.entity.StorageSpace;
import com.matrix.storage.service.StorageSpaceService;
import com.matrix.storage.vo.StorageFileVO;
import com.matrix.storage.vo.StorageSpaceVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@CrossOrigin
@RestController()
@RequestMapping("/matrix/storageSpace")
public class StorageSpaceController {

    @Autowired
    StorageSpaceService storageSpaceService;

    /**
     * 获取存储空间的内容
     * @param type  0：默认素材库 1：草稿
     */
    @GetMapping("/files")
    public Result<List<StorageFileVO>> storageSpaceFiles(int type) {
        List<StorageFileVO> files = storageSpaceService.listObjects(type);
        return Result.success(files);
    }

    //TODO: 需要修改，从header里面取
    @GetMapping("/info")
    public Result<StorageSpaceVO> getCompanyStorageSpace() {
        StorageSpaceVO storageSpaceVO = storageSpaceService.companyStorageSpaceInfo();
        return Result.success(storageSpaceVO);
    }

    @PutMapping("/info")
    public Result updateCompanyStorageSpaceInfo(StorageSpaceDTO storageSpaceDTO) {
        storageSpaceService.updateCompanyStorageSpaceInfo(storageSpaceDTO);
        return Result.success();
    }

    //TODO: 这里需要实现
    @PostMapping("/upload")
    public Result upload(MultipartFile file, int type) {
        return Result.error(StorageError.UPLOAD_FAIL);
    }
}